package com.kede.api.stand.service.impl.wxpub;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.kede.api.ienum.AppIdTypeEnum;
import com.kede.api.stand.dto.wxpub.AddDriverDTO;
import com.kede.api.stand.dto.wxpub.AddTransPortDTO;
import com.kede.api.stand.dto.wxpub.PackageInfoDTO;
import com.kede.api.stand.dto.wxpub.VailFailGoodDTO;
import com.kede.api.stand.service.LoginService;
import com.kede.api.stand.service.wxpub.IWxPubService;
import com.kede.pojo.ResHttp;
import lombok.Data;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @Author:Pr.li
 * @Date: create in 2023/10/10 21:41
 */
@Service
public class WxPubServiceImpl implements IWxPubService {

    @Resource
    private LoginService loginService;


    @Override
    public ResHttp getInfoByOpenId(String openid) {
//        $one= Db::table("t_driver")->where('openid',$openid)->find();
        return null;
    }

    @Override
    public ResHttp getWebToken(String code) {
        TokenEntity oauth2Token = getOauth2Token();
        return ResHttp.okData(oauth2Token);
    }

    @Override
    public ResHttp getJsApiTick() {
        return null;
    }

    @Override
    public ResHttp getWxJSConfig() {
        return null;
    }

    @Override
    public ResHttp addDriver(AddDriverDTO addDriverDTO) {
        return null;
    }

    @Override
    public ResHttp addTransPort(AddTransPortDTO addTransPortDTO) {
        return null;
    }

    @Override
    public ResHttp getPackageInfo(PackageInfoDTO packageInfoDTO) {
        return null;
    }

    @Override
    public ResHttp removePack(PackageInfoDTO packageInfoDTO) {
        return null;
    }

    @Override
    public ResHttp startCar(String tran_no) {
        return null;
    }

    @Override
    public ResHttp getTransPortList(String openid) {
        return null;
    }

    @Override
    public ResHttp addVailFailGood(VailFailGoodDTO vailFailGoodDTO) {
        return null;
    }

    public TokenEntity getOauth2Token(){
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("https://api.weixin.qq.com/sns/oauth2/access_token?grant_type=authorization_code");
        stringBuilder.append("&appid=");
        stringBuilder.append(AppIdTypeEnum.WX_PUBLIC.getAppid());
        stringBuilder.append("&secret=");
        stringBuilder.append(AppIdTypeEnum.WX_PUBLIC.getAppSecret());
        String s = HttpUtil.get(stringBuilder.toString());
        TokenEntity tokenEntity = JSONObject.parseObject(s, TokenEntity.class);
        tokenEntity.setTime(LocalDateTime.now().plusSeconds(7000));
        return tokenEntity;
    }

    @Data
    public static class TokenEntity{
        private String access_token;
        private Integer expires_in;
        private String openid;
        private LocalDateTime time;
    }
}
